package com.vitabuybuy.tv.ui.shopcenter.store.adapter

import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ItemShopCouponsBinding
import com.vitabuybuy.tv.dto.CouponCenterDto
import com.library.common.base.BindRecycAdapter

class ShopCouponsListAdapter : BindRecycAdapter<ItemShopCouponsBinding, CouponCenterDto>() {
    override fun onBindViewHolder(
        mBinding: ItemShopCouponsBinding,
        itemData: CouponCenterDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        if (itemData.type == mContext.getString(R.string.zhekou)) {
            mBinding.tvPrice.text = itemData.discount.toString() + mContext.getString(R.string.zhe)
        } else {
            mBinding.tvPrice.text =
                String.format(mContext.getString(R.string.price_with_value), itemData.discount)
        }
        if (itemData.precondition == 0) {
            mBinding.tvCondition.text = mContext.getString(R.string.no_threshold)
        } else {
            mBinding.tvCondition.text = String.format(
                mContext.getString(R.string.coupons_requirement),
                itemData.precondition
            )
        }
        mBinding.tvTimeRange.text = itemData.receiveStartTime + " - " + itemData.receiveEndTime
        mBinding.tvGet.setOnClickListener {
            if (itemData.isReceived) return@setOnClickListener
            saveCoupons.invoke(position)
        }
        mBinding.tvGet.text = if (itemData.isReceived)
            mContext.getString(R.string.have_got_2) else
            mContext.getString(R.string.get_2)
    }

    lateinit var saveCoupons: (position: Int) -> Unit

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_shop_coupons
    }
}
